import React, { Component } from 'react'
import propTypes from 'prop-types'

export default class Navbar extends Component {
  static propTypes = {
    event: propTypes.func,
  }

  // 指定 props 的默认值
  static defaultProps = {
    event: () => {},
  }

  render() {
    return (
      <div style={{ backgroundColor: 'yellow', height: '50px' }}>
        Navbar
        <button onClick={() => this.handleClick()}>click</button>
      </div>
    )
  }

  handleClick = () => {
    console.log('子组件中的 click')
    // 调用 父组件传来的 回调函数
    this.props.event('子组件参数传递')
  }
}
